<template>
  <div class="container">
    <div class="login-box">
      <img class="banner" src="@/assets/banner.png" alt="Library Banner"> <!-- 插入 banner 图片 -->
      <h2>图书馆座位预约系统</h2>
      <form>
        <div class="user-box">
          <input type="text" name="" required="" v-model="number">
          <label>学号/工号</label>
        </div>
        <div class="user-box">
          <input type="password" name="" required="" v-model="password">
          <label>密码</label>
        </div>
        <div class="button-container">
          <a @click="handleSubmit"  class="button">
            <span></span>
            <span></span>
            <span></span>
            <span></span>
            登录
          </a>
          <a @click="signUp_asd"  class="button">注册 </a>
        </div>
      </form>
      <a class="admin-container" @click="goToAdmin">后台管理入口</a>
    </div>
  </div>
</template>

<script>
import request from "@/req";
import { Toast } from "vant";

export default {
  name: "Login",
  data() {
    return {
      number: '',
      password: '',
    }
  },
  methods: {
    signUp_asd() {
      this.$router.replace({ path: '/register' });
    },
    goToAdmin() {
      this.$router.replace({ path: '/admin/seat/number' });
    },
    handleSubmit() {
      if (this.password === '' || this.number === '') {
        Toast.fail('请完整输入');
        return;
      }
      request.post('/public/login', {
        number: this.number,
        password: this.password
      }).then(res => {
        if (res.code === 200) {
          console.log(res);
          Toast('登陆成功');
          localStorage.setItem('user', JSON.stringify(res.user));
          if (res.user.type === 0) {
            this.$router.replace('/student/forum');
          } else if (res.user.type === 1) {
            this.$router.replace('/Teacher/seat');
          }
        } else {
          Toast('账户或密码错误');
        }
      })
    },
  },
}
</script>

<style scoped>
.container {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #a2d1ef, #4075e3);
  display: flex;
  justify-content: center;
  align-items: center;
}
@supports (-webkit-touch-callout: none) {
  container {
    height: -webkit-fill-available;
    width: -webkit-fill-available;
  }
}
.banner {
  width: 100%;
  border-radius: 5px;
  margin-bottom: 20px;
}

.login-box {
  width: 90%;
  max-width: 400px;
  padding: 40px;
  background: #b0d6e7;
  box-sizing: border-box;
  border-radius: 5px;
  text-align: center;
}

.login-box h2 {
  margin: 0 0 30px;
  padding: 0;
  color: #fff;
}

.login-box .user-box {
  position: relative;
}

.login-box .user-box input {
  width: 100%;
  padding: 10px 0;
  font-size: 16px;
  color: #fff;
  margin-bottom: 30px;
  border: none;
  border-bottom: 1px solid #fff;
  outline: none;
  background: transparent;
}

.login-box .user-box label {
  position: absolute;
  top: 0;
  left: 0;
  padding: 10px 0;
  font-size: 16px;
  color: #fff;
  pointer-events: none;
  transition: .5s;
}

.login-box .user-box input:focus ~ label,
.login-box .user-box input:valid ~ label {
  top: -20px;
  left: 0;
  color: white;
  font-size: 12px;
}

.button-container {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
}

.login-box form a {
  flex: 1;
  margin: 0 5px;
  padding: 10px 20px;
  border: 1px rgba(255, 255, 255, .3) solid;
  color: white;
  font-size: 16px;
  text-decoration: none;
  text-transform: uppercase;
  overflow: hidden;
  transition: .5s;
  letter-spacing: 4px;
  cursor: pointer;
  display: inline-block;
  text-align: center;
}

.login-box a span {
  position: absolute;
  display: block;
}

.admin-container {
  display: block;
  margin-top: 20px;
  color: white;
  text-decoration: none;
  font-size: 16px;
  transition: 0.5s;
  cursor: pointer;
}

.admin-container:hover {
  background: rgba(255, 255, 255, 0.5);
}

@media (max-width: 768px) {

  .login-box {
    width: 100%;
    padding: 20px;
  }

  .login-box form a {
    font-size: 14px;
  }



}
</style>
